package leecode

func isValidBST(root *TreeNode) bool {
	if root == nil {
		return true
	}
	var nums []int
	var searchBST func(node *TreeNode)
	searchBST = func(node *TreeNode) {
		if node == nil {
			return
		}
		searchBST(node.Left)
		nums = append(nums, node.Val)
		searchBST(node.Right)
	}
	searchBST(root)
	for i := 0; i+1 < len(nums); i++ {
		if nums[i+1] <= nums[i] {
			return false
		}
	}
	return true
}
